﻿package com.shangda.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.shangda.dao.DetectionDataDao;
import com.shangda.entity.ReceiveData;
import com.shangda.util.JdbcUtil;

public class DetectionDataDaoImpl implements DetectionDataDao{

	public void insertDetectionData(ReceiveData receiveData)
			throws Exception {
		Connection con = JdbcUtil.getConnection();
	    String sql = "insert into detection_data (sewageID,testingtime,detection1,detection2," +
	    		 	 "detection3,detection4,detection5,detection6,detection7,detection8,detection9)" +
	    		 	 "values(?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setInt(1, receiveData.getSewageId());
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();
		ps.setString(2, formatter.format(date));
		ps.setDouble(3,receiveData.getT());
		ps.setDouble(4,receiveData.getPh());
		ps.setDouble(5,receiveData.getOrp());
		ps.setDouble(6,receiveData.getLs1());
		ps.setDouble(7,receiveData.getDo());
		ps.setDouble(8,receiveData.getFlow());
		ps.setDouble(9,receiveData.getLs2());
		ps.setDouble(10,receiveData.getActuralFlow());
		ps.setDouble(11,receiveData.getSumFlow());
		ps.execute();
		JdbcUtil.release(null, ps, con);
		
	}
	
	public static void main(String[] args) {
		DetectionDataDao dao = new DetectionDataDaoImpl();
		ReceiveData receiveData = new ReceiveData();
		receiveData.setSewageId(489);
		receiveData.setT(12.3);
		receiveData.setPh(12.3);
		receiveData.setDo(12.3);
		receiveData.setActuralFlow(12.3);
		receiveData.setFlow(12.3);
		receiveData.setOrp(12.3);
		receiveData.setSumFlow(12.3);
		try {
			dao.insertDetectionData(receiveData);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	

}
